<?php

//Security using IDS PHP
 require_once 'Init.php';
    $request = array(
        'REQUEST' => $_REQUEST,
        'GET' => $_GET,
        'POST' => $_POST,
        'COOKIE' => $_COOKIE
    );
    $init = IDS_Init::init( 'IDS/Config/Config.ini.php');
    $init->config['General']['base_path'] = 'IDS/';
    $init->config['General']['use_base_path'] = true;
    $init->config['Caching']['caching'] = 'none';

    // 2. Initiate the PHPIDS and fetch the results
    $ids = new IDS_Monitor($request, $init);
    $result = $ids->run();

   if (!$result->isEmpty()) {
        
        if ($result->getImpact()>40)
            {
            //if (isset($_SESSION['admin']))
              //  if ($_SESSION['admin']==1)
                //    if ($result->getImpact()>110)
                  //  {
            $to = array();
            $to['danielpopescu93@gmail.com']='Daniel Popescu';
            //$users = $this->User->find('all',array('conditions'=>array('role'=>'admin')));
            
            $from = array('danielpopescu93@gmail.com' =>'Acatist');
            
            $subject = 'Threat detected on acatist';
            
            $html = "<p>IP: ".$_SERVER['REMOTE_ADDR']. "<br />". "URL: ".$_SERVER['REQUEST_URI']. "<br />"."Impact: ".$result->getImpact().'</p>';
            
            $transport = Swift_SmtpTransport::newInstance(SMTP_MANDRILL_URL,SMTP_MANDRILL_PORT);
            $transport->setUsername(SMTP_MANDRILL_USER);
            $transport->setPassword(SMTP_MANDRILL_PASS);
            $swift = Swift_Mailer::newInstance($transport);
            
            $message = new Swift_Message($subject);
            $message->setFrom($from);
            $message->setBody($html, 'text/html');
            $message->setTo($to);
                    
                    $recipients = $swift->send($message, $failures);
            
            
            header('Location: '.SITE_URL.'errors/errorsecurity');
            exit();
            }
        }
?>